package com.yao.component.pictureselector.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.yao.component.pictureselector.ImageLoader;
import com.yao.component.pictureselector.R;
import com.yao.component.pictureselector.bean.ImageFloder;
import com.yao.sdk.glide.GlideUtil;

import java.io.File;
import java.util.List;

/**
 * Created by zwj on 2016/1/19.
 */
public class VideoDirAdapter extends BaseAdapter {
    private List<ImageFloder> mList;
    private Context mContext;
    public VideoDirAdapter(Context context, List<ImageFloder> list){
        this.mContext=context;
        this.mList=list;
    }
    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView==null){

            convertView= LayoutInflater.from(mContext).inflate(R.layout.image_dir_item, null);

            new Holder(convertView);
        }
        Holder holder=(Holder) convertView.getTag();
        GlideUtil.getInstance().loadVideo(mContext,new File(mList.get(position).getFirstImagePath()),holder.imageView);
//        ImageLoader.getInstance(3, ImageLoader.Type.LIFO).loadImage(mList.get(position).getFirstImagePath(), holder.imageView);
        holder.name.setText(mList.get(position).getName());
        holder.count.setText("("+mList.get(position).getCount()+")");


        return convertView;
    }
    private class Holder{
        private ImageView imageView;
        private TextView name,count;
        public Holder(View convertView) {
            imageView=(ImageView) convertView.findViewById(R.id.pic);
            name=(TextView)convertView.findViewById(R.id.dir_name);
            count=(TextView)convertView.findViewById(R.id.dir_count);
            convertView.setTag(this);
        }
    }
}
